package com.bhs.sansong.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansong.R;
import com.bhs.sansong.bean.OrderGoodsBean;
import com.bhs.sansong.utils.DateUtils;
import com.bhs.sansong.utils.MyUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class OrderGoodsAdapter extends BaseQuickAdapter<OrderGoodsBean, BaseViewHolder> {

    public OrderGoodsAdapter() {
        super(R.layout.item_order);
    }

    private String type;

    public OrderGoodsAdapter(String type) {
        super(R.layout.item_order);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OrderGoodsBean item) {
        helper.addOnClickListener(R.id.btn_check_logistics, R.id.btn_confirm_receipt, R.id.btn_check_view_offer2,
                R.id.btn_one_more, R.id.btn_check_cancel, R.id.btn_relaunch, R.id.tv_order_number,
                R.id.btn_pay, R.id.btn_evaluate);
        helper.setGone(R.id.btn_evaluate, item.getStatus() == 20 && item.getComment_status().equals("0"));
        helper.setGone(R.id.btn_pay, item.getStatus() <= 20 && !TextUtils.isEmpty(item.getNo_pay_total()) && Double.parseDouble(item.getNo_pay_total()) > 0);
        helper.setGone(R.id.btn_appoint, item.getOrder_type() == 1);//1指派 2极速
        helper.setGone(R.id.btn_top_speed, item.getOrder_type() == 2);
        helper.setGone(R.id.btn_make_appointment, item.getIs_yuyue() > 0);
        helper.setText(R.id.tv_order_number, String.format("订单号:%s", item.getDeliver_sn()));
        helper.setText(R.id.tv_place_departure, item.getPickup_city());
        helper.setText(R.id.tv_destination, item.getReceive_city());
        helper.setText(R.id.tv_delivery_type, MyUtils.getDeliveryType(item.getJiaohuo_type()));
        helper.setGone(R.id.btn_relaunch, item.getStatus() == 90);
        helper.setGone(R.id.btn_confirm_receipt, item.getStatus() == 15);
        helper.setGone(R.id.btn_check_view_offer2, item.getQuoted_num() > 0 && item.getStatus() == 3);
        helper.setGone(R.id.btn_check_logistics, item.getStatus() > 3 && item.getStatus() < 20);
        TextView tvStatus = helper.getView(R.id.tv_status);
        if (TextUtils.isEmpty(type)) {
            tvStatus.setText(item.getStatus_msg());
            if (item.getStatus() == 20) {
                tvStatus.setTextColor(Color.parseColor("#000000"));
            } else if (item.getStatus() == 80 || item.getStatus() == 90) {
                tvStatus.setTextColor(Color.parseColor("#FF6067"));
            } else {
                tvStatus.setTextColor(Color.parseColor("#485EF4"));
            }
        } else {
            //询价相关
            tvStatus.setTextColor(Color.parseColor("#485EF4"));
            tvStatus.setText(MyUtils.setStatus(type));
            helper.addOnClickListener(R.id.btn_closing_inquiry, R.id.btn_check_view_offer);
            helper.setText(R.id.tv_view_offer, String.format("%s人报价", item.getQuoted_num()));
            helper.setGone(R.id.btn_check_view_offer, item.getQuoted_num() > 0 || !type.equals("1"));
            helper.setGone(R.id.btn_closing_inquiry, type.equals("1"));
            helper.setVisible(R.id.tv_view_offer, type.equals("1"));
        }


        helper.setGone(R.id.ll_operation, TextUtils.isEmpty(type));
        helper.setGone(R.id.ll_operation2, !TextUtils.isEmpty(type));
        helper.setText(R.id.tv_distribution_type, MyUtils.getDistributionType(item.getPeisong_type()));
        if (item.getIs_yuyue() > 0 && item.getStatus() == 5) {
            helper.setText(R.id.tv_order_time, String.format("预约时间：%s", DateUtils.descriptiveData(item.getYuyue_time())));
        } else {
            helper.setText(R.id.tv_order_time, String.format("下单时间：%s", DateUtils.descriptiveData(item.getCreate_time())));
        }
        TextView tvOrderPrice = helper.getView(R.id.tv_order_price);
        if (!TextUtils.isEmpty(item.getNo_pay_total()) && Double.parseDouble(item.getNo_pay_total()) > 0) {
            tvOrderPrice.setText(String.format("￥%s", item.getNo_pay_total()));
        } else {
            tvOrderPrice.setText("");
        }

    }
}
